﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WMS.FC.Domain.PersistenceObject.Business;
using WMS.FC.Infrastructure.Common;

namespace WMS.FC.Infrastructure.POConfig.Business
{
    public class EquipmentConfig : POBaseConfig<EquipmentPO>
    {
        public override void InitializeData(EntityTypeBuilder<EquipmentPO> builder)
        {
        }

        public override void MapColumn(EntityTypeBuilder<EquipmentPO> builder, ref int index)
        {
            builder.HasComment("设备表");
            builder.Property(entity => entity.Code).ConfigColumn("CODE", "编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.Name).ConfigColumn("NAME", "名称", 100, true).HasColumnOrder(index++);
            builder.Property(entity => entity.LineCode).ConfigColumn("LINE_CODE", "产线编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.ZoneCode).ConfigColumn("ZONE_CODE", "区域编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.TypeCode).ConfigColumn("TYPE_CODE", "类型编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.StateCode).ConfigColumn("STATE_CODE", "状态编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.UseStateCode).ConfigColumn("USE_STATE_CODE", "使用状态编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.SupplierServerAddress).ConfigColumn("SUPPLIER_SERVER_ADDRESS", "供应商服务地址", 100).HasColumnOrder(index++);
            builder.Property(entity => entity.SupplierModeCode).ConfigColumn("SUPPLIER_MODE_CODE", "供应商模式编码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.SupplierStateCode).ConfigColumn("SUPPLIER_STATE_CODE", "供应商状态编码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.EmptyTrayCache).ConfigColumn("EMPTY_TRAY_CACHE", "空托盘缓存数量").HasColumnOrder(index++);
            builder.Property(entity => entity.WarehouseCode).ConfigColumn("WAREHOUSE_CODE", "仓库编码", 50, true).HasColumnOrder(index++);
        }

        public override void MapIndex(EntityTypeBuilder<EquipmentPO> builder)
        {
            builder.HasIndex(entity => new { entity.Code, entity.WarehouseCode, entity.LineCode }).HasDatabaseName($"UN_{TableName}_1").IsUnique();
        }
    }
}
